package com.jida.hadoop.mr.wz.countpv;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.jida.hadoop.mr.wz.dataclean.TProperties;

public class CountPvMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
	private final static IntWritable one = new IntWritable(1);
	private Text word = new Text();
	@Override
	public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
		StringTokenizer itr = new StringTokenizer(value.toString());
		while (itr.hasMoreTokens()) {
			String str = itr.nextToken().toString();
			String substr1 = str.substring(0,6);
			String substr2 = str.substring(18);
			str = substr1 + "000000000000" + substr2;
			String[] splits = str.split(TProperties.getValue("fileoutsplit"));
			word.set(splits[0] + "|" + splits[1]);
			context.write(word, one);
		}
	}
}
